/*
 * Copyright 2008 Jens Meiss
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hmvc4gwt.client.controller;

import hmvc4gwt.client.component.IComponent;
import hmvc4gwt.client.event.IEvent;
import hmvc4gwt.client.event.IEventListener;
import hmvc4gwt.client.model.IModel;
import hmvc4gwt.client.view.IView;

/**
 * Extend this IController-Implementation to get an fully-featured and
 * configured Controller-Component.
 * 
 * @author jens.meiss
 * 
 */
public abstract class AController implements IController {

	/**
	 * the component object
	 */
	private IComponent component;

	/**
	 * is the controller initialized
	 */
	private boolean initialized = false;

	/**
	 * is the controller terminated
	 */
	private boolean terminated = false;

	public IComponent addChildComponent(IController controller) {
		return component.addChildComponent(controller);
	}

	public IComponent addChildComponent(IController controller, IModel model) {
		return component.addChildComponent(controller, model);
	}

	public IComponent addChildComponent(IController controller, IModel model,
			IView view) {
		return component.addChildComponent(controller, model, view);
	}

	public IComponent addChildComponent(IController controller, IView view) {
		return component.addChildComponent(controller, view);
	}

	public final void fireEvent(IEvent event, boolean up, boolean local,
			boolean down) {
		component.fireEvent(event, up, local, down);
	}

	public void fireEventLocal(IEvent event) {
		component.fireEvent(event, false, true, false);
	}

	public void fireEventDown(IEvent event) {
		component.fireEvent(event, false, false, true);
	}

	public void fireEventUp(IEvent event) {
		component.fireEvent(event, true, false, false);
	}

	public IComponent getComponent() {
		return component;
	}

	public IModel getModel() {
		return component.getModel();
	}

	public IView getView() {
		return component.getView();
	}

	public boolean isInitialized() {
		return initialized;
	}

	public boolean isTerminated() {
		return terminated;
	}

	public void post() {
	}

	public void pre() {
	}

	public void register(Class classOfEvent, IEventListener listener) {
		component.register(classOfEvent, listener);
	}

	public void setComponent(IComponent component) {
		this.component = component;
	}

	public void setInitialized(boolean initialized) {
		this.initialized = initialized;
	}

	public void setTerminated(boolean b) {
		component.setTerminated(b);
	}

}
